package com.wanshi.controller;

import com.wanshi.po.Result;
import com.wanshi.po.User;
import com.wanshi.po.UserPo;
import com.wanshi.service.UserService;
import com.wanshi.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("dati")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/getScoreListOfCls")
    public String getScoreListOfCls(Model model, HttpSession session) {
        User user = (User)session.getAttribute("user");
        List<UserPo> list = userService.getScoreListOfCls(user.getClsname());

        model.addAttribute("list",list);
        return "listScore";
    }

    @RequestMapping("/getScoreListOfClsAjax")
    @ResponseBody
    public Result getScoreListOfClsAjax(String clsname) {
        List<UserPo> list = userService.getScoreListOfCls(clsname);
        return new Result(Constants.SUCCESS,"",list);
    }

    @RequestMapping("/getCls")
    public String getCls(Model model, HttpSession session) {

        List<String> list = userService.getCls();

        model.addAttribute("list",list);
        return "listCls";
    }

}
